<!doctype html>
<html lang="zh">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
    <title>发布帖子</title>
    <link href="https://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="http://cdn.bootcss.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../css/default.css">
    <link href="../css/editor.css" type="text/css" rel="stylesheet"/>
    <script src="../static/js/jquery-1.10.2.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    <script src="../js/editor.js"></script>
    <link href="https://fonts.googleapis.com/css?family=Material+Icons" rel="stylesheet">
    <link href="../static/css/vuetify.min.css" rel="stylesheet">
    <script src="../static/js/vue.js"></script>
    <script src="../static/js/vuetify.js"></script>
    <link rel="stylesheet" href="../static/css/login.css">
    <link rel="stylesheet" href="../static/css/bootstrap-select.css">
    <script src="../static/js/bootstrap-select.js"></script>
    <script type="text/javascript" src="../js/include.js"></script>
    <script type="text/javascript" src="../js/includebody.js"></script>
    <script src="../static/js/axios.min.js"></script>
    <script src="../static/js/jquery.cookie.js"></script>
</head>
<body>
<div id="headerbody"></div>
<div class="row mt-4" id="tp_tpublish">
    <div class="col-md-10 col-md-offset-1 col-sm-10 col-sm-offset-1 col-xs-12">
        <div class="panel panel-success">
            <div class="panel-heading">
                <h3 class="panel-title">投递新闻</h3>
            </div>
            <div class="panel-body">
                <div class="alert alert-info" role="alert">您投递的新闻经过编辑审核通过后将在 资讯页面 显示</div>
                <form class="form-horizontal" role="form">
                    <span>请选择所属模块</span>
                    <div class="row" id="aaa">
                        <div class="col-md-3 col-sm-6 col-xs-8" style="margin-bottom: 15px">
                            <select id="s1" class=" form-control" v-model="fId">
                                <option value="0">请选择</option>
                            </select>
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-8" style="margin-bottom: 15px">
                            <select id="s2" class=" form-control" v-model="fbId">
                                <option value="0">请选择</option>
                            </select>
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-8" style="margin-bottom: 15px">
                            <select id="s3" class=" form-control" v-model="lbId">
                                <option value="0">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-xs-12">
                            <input type="text" class="form-control" id="titlename" v-model="title"
                                   placeholder="请输入标题">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-12 nopadding">
                            <textarea id="txtEditor" class="form-control"></textarea>

                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-xs-10">
                            <button type="button" id="submit" class="btn btn-primary" @click="count()">发布帖子</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $("#txtEditor").Editor();
        $.ajax({
            type: "POST",
            //dataType: "application/json",
            url: "/LxCommunity/forum/findall",
            success: function (result) {
                var dataObj = result;
                $.each(dataObj, function (index, item) {
                    var d1 = dataObj[index].fId;
                    var d2 = dataObj[index].forumtitle;
                    console.log(d1 + ":" + d2);
                    $("#s1").append("<option value='" + d1 + "'>" + d2 + "</option>");

                });
            }
        });

        $("#s1").change(function () {
            console.log($(this).val());
            var id = $(this).val();
            $.ajax({
                type: "POST",
                //dataType: "application/json",
                data: {"id": id},
                url: "/LxCommunity/forumBody/findByFid",
                success: function (result) {
                    var dataObj = result;
                    $("#s2 option").remove();
                    $("#s2").append("<option value='0'>请选择</option>");
                    $.each(dataObj, function (index, item) {
                        var d1 = dataObj[index].fbId;
                        var d2 = dataObj[index].kind;
                        $("#s2").append("<option value='" + d1 + "'>" + d2 + "</option>");
                    });
                }
            });
        });

        $("#s2").change(function () {
            var id = $(this).val();
            $.ajax({
                type: "POST",
                data: {"id": id},
                url: "/LxCommunity/label/findlabelbyfbid",
                success: function (result) {
                    var dataObj = result;
                    $("#s3 option").remove();
                    $("#s3").append("<option value='0'>请选择</option>");
                    $.each(dataObj, function (index, item) {
                        var d1 = dataObj[index].lId;
                        var d2 = dataObj[index].ltitle;
                        $("#s3").append("<option value='" + d1 + "'>" + d2 + "</option>");
                    });
                }
            });
        });


    });
    $(function () {
        if ($.cookie('userid') == null) {
            var editor = $(".Editor-editor");

            editor.html('<div style="text-align: center;"><font size="6">你还没有登录，不能发表博客&nbsp;&nbsp;<a href="LxCommunity/html/login.html" id="ssssss">登录</a>&nbsp;&nbsp;<a href="LxCommunity/html/register.html" id="ssssss1">注册</a></font><br></div>')

            $("#ssssss").click(function () {
                window.location.href = "/LxCommunity/html/login.html"
            });
            $("#ssssss1").click(function () {
                window.location.href = "/LxCommunity/html/register.html"
            })
        }
        $("#submit").click(function () {


            console.info($.cookie('username'))
            console.info($.cookie('userid'))


            if ($.cookie('userid') != null)
                var editor = $(".Editor-editor");

        });


    })


</script>
<div id="footerbody"></div>
<script>
    new Vue({
        el: "#tp_tpublish",
        data() {
            return {
                fId: '',
                fbId: '',
                title: '',
                lbId: '',
                content: ''
            }
        },
        methods: {
            count: function () {
                this.content = $(".Editor-editor").html()
                if (this.fId == null || this.fbId == null || this.lbId == null) {

                    return;
                } else if (this.title == null) {

                    return;
                } else if (this.content==null) {

                    return;
                }


                axios.post("/LxCommunity/content/instercontent", {
                    uId: $.cookie("userid"),
                    fId: this.fId, // 搜索条件
                    fbId: this.fbId,// 当前页
                    title: this.title,// 每页大小
                    lbId: this.lbId,// 排序字段
                    content: this.content,// 是否降序
                    publicationTime: new Date()

                }).then(resp => { // 这里使用箭头函数
                    this.brands = resp.data.items;
                    this.totalBrands = resp.data.total;
                    // 完成赋值后，把加载状态赋值为false
                    this.loading = false;
                })


            }
        },


    })
</script>
</body>
</html>